Page({
  data: {
    // 功能模块列表
    modules: [{
        title: '常用应用',
        children: [{
          title: '待处理',
          icon: '/assets/img/pendingprocess.svg',
          level: 0x000101,
          url: '/pages/sys/commonUseModules/pendingProcessing/pendingProcessing'
        }, {
          title: '已处理',
          icon: '/assets/img/processed.svg',
          level: 0x000102,
          url: '/pages/sys/commonUseModules/processed/processed'
        }],
        id: 6,
      },
      {
        title: '基础应用',
        children: [{
          title: '请假',
          icon: '/assets/img/leave.svg',
          level: 0x000001,
          url: '/pages/sys/baseModules/leave/leave'
        }, {
          title: '出差',
          icon: '/assets/img/evection.svg',
          level: 0x000002,
          url: '/pages/sys/baseModules/evection/evection'
        }],
        id: 0
      },
      {
        title: '综合行政管理',
        children: [{
            title: '采购申请',
            icon: '/assets/img/purchasingrequisition.svg',
            level: 0x010001,
            url: '/pages/sys/adminModules/purchasRequisit/purchasRequisit'
          }, {
            title: '采购确认',
            icon: '/assets/img/purchaseconfirmation.svg',
            level: 0x010102,
            url: '/pages/sys/adminModules/purchasedConfirmation/purchasedConfirmation'
          }, {
            title: '用印申请',
            icon: '/assets/img/sealapplication.svg',
            level: 0x010003,
            url: '/pages/sys/adminModules/sealApplication/sealApplication'
          }, {
            title: '议题申请',
            icon: '/assets/img/issuerequest.svg',
            level: 0x010004,
            url: '/pages/sys/adminModules/topicApplication/topicApplication'
          }, {
            title: '会议纪要',
            icon: '/assets/img/minutesmeeting.svg',
            level: 0x010205,
            url: '/pages/sys/adminModules/meetingMinutes/meetingMinutes'
          }, {
            title: '合同审批',
            icon: '/assets/img/contractapprove.svg',
            level: 0x010006,
            url: '/pages/sys/adminModules/contractManage/contractManage'
          }, {
            title: '薪资审批',
            icon: '/assets/img/salary.svg',
            level: 0x010006,
            url: '/pages/sys/adminModules/payrollApproval/payrollApproval'
          },
          // {
          //   title: '会议室申请',
          //   icon: '/assets/img/meetingroom.svg',
          //   level: 0x010007,
          //   url: '/pages/sys/adminModules/meetRoomApplication/meetRoomApplication'
          // }
        ],
        id: 1
      },
      {
        title: '财务管理',
        children: [{
          title: '开票功能',
          icon: '/assets/img/invoicing.svg',
          level: 0x020001,
          url: '/pages/sys/financeModules/invoicingFunction/invoicingFunction'
        }, {
          title: '开收据功能',
          icon: '/assets/img/receipt.svg',
          level: 0x020002,
          url: '/pages/sys/financeModules/issueReceipt/issueReceipt'
        }, {
          title: '报销功能',
          icon: '/assets/img/expenseaccount.svg',
          level: 0x020003,
          url: '/pages/sys/financeModules/expenseAccount/expenseAccount'
        }, {
          title: '付款功能',
          icon: '/assets/img/payment.svg',
          level: 0x020104,
          url: '/pages/sys/financeModules/paymentFunction/paymentFunction'
        }, ],
        id: 2
      },
      {
        title: '实验室管理',
        children: [{
            title: '设备试验',
            icon: '/assets/img/device.svg',
            level: 0x040001,
            url: '/pages/sys/laboratoryModules/deviceManagementV2/deviceManagementV2'
          },
          {
            title: '订单录入',
            icon: '/assets/img/orderforgoods.svg',
            level: 0x040002,
            url: '/pages/sys/laboratoryModules/orderEntry/orderEntry'
          },
          {
            title: '订单管理',
            icon: '/assets/img/ordermanagement.svg',
            level: 0x040002,
            url: '/pages/sys/laboratoryModules/OrderManagement/OrderManagement'
          },
          {
            title: '耗材申请',
            icon: '/assets/img/consumables.svg',
            level: 0x040003,
            url: '/pages/sys/laboratoryModules/consumablesApplication/consumablesApplication'
          },
          {
            title: '耗材库',
            icon: '/assets/img/consumableslibrary.svg',
            level: 0x040003,
            url: '/pages/sys/laboratoryModules/consumablesLibrary/consumablesLibrary'
          },
          {
            title: '台账导出',
            icon: '/assets/img/ledgermanagement.svg',
            level: 0x040003,
            url: '/pages/sys/laboratoryModules/ledgerManagement/ledgerManagement'
          }
        ],
        id: 3
      },
      {
        title: '项目管理',
        children: [{
          title: '项目归档',
          icon: '/assets/img/information.svg',
          level: 0x080001,
          url: '/pages/sys/ProjectModules/ProjectArchiving/ProjectArchiving'
        }],
        id: 4
      },
      {
        title: '流片业务',
        children: [
          // {
          //   title: '流片议题',
          //   icon: '/assets/img/issuerequest.svg',
          //   level: 0x010004,
          //   url: '/pages/sys/TapeoutBusiness/TapeOutIssues/TapeOutIssues'
          // },
          // {
          //   title: '流片纪要',
          //   icon: '/assets/img/minutesmeeting.svg',
          //   level: 0x010205,
          //   url: '/pages/sys/TapeoutBusiness/tapeOutMinutes/tapeOutMinutes'
          // },
          {
            title: '议题和合同',
            icon: '/assets/img/contractapprove.svg',
            level: 0x010006,
            url: '/pages/sys/TapeoutBusiness/tapeOutContracts/tapeOutContracts'
          },
          {
            title: '流片付款',
            icon: '/assets/img/currentsheet.svg',
            level: 0x100001,
            url: '/pages/sys/TapeoutBusiness/tapeoutPayments/tapeoutPayments'
          }
        ],
        id: 5
      },
      //01052133605426110345
      {
        title: '参数设置',
        level: '01052133605426110345',
        children: [{
            title: '流程配置',
            icon: '/assets/img/processconfiguration.svg',
            level: '01052133605426110345',
            url: '/pages/sys/configurationModules/conditionConfiguration/conditionConfiguration'
          },
          {
            title: '设备绑定',
            icon: '/assets/img/devicebind.svg',
            level: '01052133605426110345',
            url: '/pages/sys/configurationModules/deviceBinding/deviceBinding'
          },
          {
            title: '假期设置',
            icon: '/assets/img/holiday.svg',
            level: '01052133605426110345',
            url: '/pages/sys/configurationModules/leaveConfiguration/leaveConfiguration'
          }
        ],
        id: 5
      },
      //manager4797
      // {
      //   title: '参数设置',
      //   level:'manager4797',
      //   children: [{
      //     title: '流程配置',
      //     icon: '/assets/img/processconfiguration.svg',
      //     level: 'manager4797',
      //     url: '/pages/sys/configurationModules/conditionConfiguration/conditionConfiguration'
      //   },
      //   {
      //     title: '设备绑定',
      //     icon: '/assets/img/devicebind.svg',
      //     level: 'manager4797',
      //     url: '/pages/sys/configurationModules/deviceBinding/deviceBinding'
      //   },
      //   {
      //     title: '假期设置',
      //     icon: '/assets/img/holiday.svg',
      //     level: 'manager4797',
      //     url: '/pages/sys/configurationModules/leaveConfiguration/leaveConfiguration'
      //   }
      //   ],
      //   id: 5
      // },
    ],
    userId: ''
  },

  onShow() {
    let position = '';
    let dept = '';

    my.getStorage({
      key: 'userInfo',
      success: (res) => {
        console.log('userId', res.data.result.userid);
        this.setData({
          userId: res.data.result.userid
        })
        // console.log(res);
        // position = [res.data.details.result[0].field_data_list.filter(it => it.field_code === 'sys00-position')[0].field_value_list[0].value]
        // dept = res.data.details.result[0].field_data_list.filter(it => it.field_code === 'sys00-dept')[0].field_value_list[0].value.split(',')

        // console.log(position, dept);

        // 04 08 10

        // const baseLevel = 0xfbffff
        // const levelTable = [
        //   { l: '研发部', val: 0x04000 },
        //   { l: '董事长', val: 0xffff00 },
        //   { l: '总经理', val: 0xffff00 },
        //   { l: '副总经理', val: 0xffff00 },
        // ]

        // position = '职员'

        // const userLevel = levelTable.map(it => {
        //   if (dept.includes(it.l) || position.includes(it.l)) {
        //     return it.val
        //   }
        // }).filter(it => {
        //   if (it) {
        //     return it
        //   }
        // }) | baseLevel

        // console.log(userLevel);

        const modules = this.data.modules.filter(it => {
          // console.log('LOG', it.level);
          if (it.level === undefined) return true
          else if (it.level === this.data.userId) return true
          else return false
        })

        // console.log('LOG',modules);

        // modules = modules.map(it => ({
        //   ...it, children: it.children.filter(c => {
        //     // console.log('level', c.level);
        //     // console.log('userLevel', userLevel);
        //     // console.log('result', userLevel & c.level);
        //     if (c.level & userLevel !== 0) {
        //       return true
        //     }
        //     else {
        //       return false
        //     }
        //   })
        // }))
        // modules = modules.filter(it => it.children.length > 0)
        this.setData({
          modules
        })

      }
    })

  },

  modulesClick: (e) => {
    const level = e.target.dataset.level;
    const url = e.target.dataset.url;

    if (!level || !url) {
      my.alert({
        title: 'Warning',
        content: '该功能未开放！'
      })
      return
    } else {

      my.navigateTo({
        url
      })
    }
  }
});